package cn.memset.sample;

import cn.memset.sample.classloaders.MyCommonClassLoader;
import com.sun.javafx.util.Logging;

import java.lang.reflect.Array;

/**
 * 数组类关联的类加载器
 */
public class ArrayClassLoaderTest {
    public static void main(String[] args) throws Exception {
        int[] ia = new int[0];
        System.out.println("int数组:" + ia.getClass().getClassLoader());

        String[] sa = new String[0];
        System.out.println("String数组:" + sa.getClass().getClassLoader());

        Logging[] la = new Logging[0];
        System.out.println("Logging数组:" + la.getClass().getClassLoader());

        ArrayClassLoaderTest[] aa = new ArrayClassLoaderTest[0];
        System.out.println("ArrayClassLoaderTest数组:" + aa.getClass().getClassLoader());

        ClassLoader myLoader = new MyCommonClassLoader("E:\\Work\\Workspace\\JavaCode\\Demo\\java-classloader-sample\\app-service\\target\\classes");
        Class<?> serviceCls = Class.forName(
                "cn.memset.app.CompanyService",
                true,
                myLoader);

        Object[] oa = (Object[]) Array.newInstance(serviceCls, 0);
        System.out.println("CompanyService数组:" + oa.getClass().getClassLoader());
    }
}
